import { defineConfig } from "vite";
import Vue from "@vitejs/plugin-vue";
import UnoCSS from 'unocss/vite'
import AutoImport from "unplugin-auto-import/vite"
import Components from "unplugin-vue-components/vite"
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'

export default defineConfig({
  plugins: [
    Vue(),
    UnoCSS(),
    AutoImport({
      resolvers: [ElementPlusResolver()],
    }),
    Components({
      resolvers: [ElementPlusResolver()],
    }),
    AutoImport({
      imports: ["vue", "vue-router", "pinia"],
      dts: './auto-imports.d.ts',
    }),
  ],
  resolve: {
    alias: {
      "@": "/src"
    }
  },
  server: {
    proxy: {
      '/api': {
        target: 'http://localhost:3000', // 你的后端服务器地址
        changeOrigin: true, //  是否更改请求来源
        rewrite: (path) => {
          console.log(path);
          
          return path.replace(/^\/api/, '')
        } // 可选: 修改路径
      }
    }
  }
});
